<template>
	<view class="content">
		<view class="topNav">
			<view class="topNav" style="margin:0 -32rpx ;padding32rpx ;height: 90rpx;">
				<div class="cuIcon-back icon left" @click="back"></div>
				<div class="center">详情页</div>
				<!-- <div class='right'>
					<div class='cuIcon-favor' v-show='!is_collection' @click='collection'></div>
					<div class='cuIcon-favorfill' style='color: #a67200;' v-show='is_collection' @click='notCollection'>
					</div>
				</div> -->
			</view>
		</view>
		<div style="width: 100%;height: 90rpx;"></div>
		<div class='bookCont'>
			<img :src="data.image" class='bookImg'>
			<div class='bookNmae'>{{data.name}}</div>
			<div class='authorNmae'>{{data.author}}</div>
			<div class='text'>
				<!-- <div class='title'>简介</div> -->
				<div class='textCont'>{{data.describe}}</div>
				<div class='myBtn' @click='toNext()'>开始学习</div>
			</div>
		</div>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				from: 2,
				data: {},
				is_collection: false,
			}
		},
		onLoad(e) {
			//console.log('e==入参===', e)
			this.id = e.id
			this.from = e.from || 2
		},
		onShow() {

			this.getData()
			//console.log('执行了onShow')
		},
		mounted() {},
		methods: {
			back() {
				// uni.navigateBack()

				if (this.from == 5) {
					uni.navigateTo({
						url: `/pages/my/readingRecord`
					});
				} else {
					uni.navigateTo({
						url: `/pages/index/index?type=${this.from}`
					});
				}
			},
			getData() {
				let _this = this;
				_this.uniRequest({
					url: `/books/detail`,
					method: 'post',
					data: {
						id: _this.id
					},
					success: res => {
						//console.log('返回值', res);
						if (res.code == 200) {
							this.data = res.data.book;
							this.is_collection = res.data.is_collection
						}
					},
					fail: err => {
						//console.log('request fail错误', err);
					}
				});
			},
			collection() {
				let _this = this;
				_this.uniRequest({
					url: `/books/collection`,
					method: 'post',
					data: {
						book_id: _this.id
					},
					success: res => {
						//console.log('返回值', res);
						if (res.code == 200) {
							this.is_collection = true
						}
					},
					fail: err => {
						//console.log('request fail错误', err);
					}
				});
			},
			notCollection() {
				let _this = this;
				_this.uniRequest({
					url: `/books/un_collection`,
					method: 'post',
					data: {
						book_id: _this.id
					},
					success: res => {
						//console.log('返回值', res);
						if (res.code == 200) {
							this.is_collection = false
						}
					},
					fail: err => {
						//console.log('request fail错误', err);
					}
				});
			},
			toNext() {
				uni.navigateTo({
					url: `/pages/book/bookDetails?id=${this.data.id}&from=${this.from}`
				});
			},
		}
	}
</script>

<style lang='less' scoped>
	.content {
		background: #eae9e5;
		background-image: url(../../static/imgs/bookbj.png);
		background-repeat: no-repeat;
		background-size: 100% 100%;
		min-height: 100vh;

		.topNav {
			background: #1C81DF;
			color: white;
			background: transparent;
			color: #000000;
			color: #a47709;
		}

		.bookCont {
			width: 690rpx;
			margin: 32rpx auto;
			min-height: 100rpx;
			border: 2px solid #E8E8E8;
			border-radius: 20rpx;
			text-align: center;
			background: #eae9e5;
			background: transparent;

			.bookImg {
				width: 310rpx;
				height: 400rpx;
				border-radius: 12rpx;
				margin-top: 66rpx;
			}

			.bookNmae {
				font-size: 54rpx;
				font-weight: bold;
				color: #181E27;
				margin: 40rpx 0 10rpx;
			}

			.authorNmae {
				font-size: 36rpx;
				font-weight: normal;
				color: #1C81DF;
				margin-bottom: 12rpx;
				color: #b88d53;
			}

			.text {
				padding: 32rpx;
				width: 100%;
				box-sizing: border-box;
				background: #FFFFFF;
				border-radius: 20rpx;
				text-align: left;
				line-height: 48rpx;
				background: #eae9e5;
				background: transparent;

				.title {
					width: 37px;
					height: 18px;
					font-size: 18px;
					font-family: Hiragino Sans GB;
					font-weight: bold;
					color: #646972;
					padding-bottom: 32rpx;
				}

				.textCont {
					font-size: 15px;
					font-weight: normal;
					color: #181E27;
					/* padding-bottom: 100rpx; */
					text-align: center;
				}

				.myBtn {
					width: calc(100% - 32rpx);
					margin: 0 auto;
					height: 98rpx;
					/* background: linear-gradient(90deg, #41B2F6 0%, #1C81DF 100%); */
					border-radius: 48rpx;
					text-align: center;
					font-size: 30rpx;
					font-weight: normal;
					color: #FFFFFF;
					line-height: 98rpx;
					border-radius: 12rpx;
					width: calc(100% - 0rpx);
					margin: 80rpx auto 0;
					background-color: #a47203;
				}
			}
		}
	}
</style>
